import { API_LIST } from '../../../Api/Api'
import { commonTableList } from '../Common/common'
import { OpenExcelButton, InputButton, SelectExcelButton } from '../Common/options'
import { winningBidder } from '../Common/Conversion'

export const GetWinningBidderScore = async ({ url, OptionsEvent, ClientData, Permission, actionRef }) => {
    let data = {
        type: '项目评分',
        pageSize: 10,
        params: { pageIndex: 1 },
        get: API_LIST()[`getScoreManagementGetWinningBidderScore`],
        options: [
            <SelectExcelButton
                key="excel"
                title="下载Excel"
                OptionsEvent={OptionsEvent}
                api={API_LIST()['getWinningBidderScoreListExcel']}
            />,
        ],
        columns: [
            commonTableList.uuid,
            {
                dataIndex: 'winningBidderUuid',
                title: '中标单位',
                valueType: 'select',
                valueEnum: await winningBidder(),
                rules: true,
                width: 450,
            },
            {
                dataIndex: 'yearMonth',
                title: '年月',
                valueType: 'Date',
                picker: 'month',
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'yWinningBidderScore',
                title: '原分数',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'problemScore',
                title: '问题分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'addScore',
                title: '加分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                dataIndex: 'winningBidderScore',
                title: '最终得分',
                valueType: 'input',
                rules: true,
                width: 100,
                hideInSearch: true,
            },
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    const { winningBidderUuid, yearMonth } = record
                    return [
                        Permission.findIndex(v => v.uuid === 'ec1c31dd-37c8-46cf-9cc4-b80437bc6fd5') !== -1 && (
                            <OpenExcelButton
                                key="open"
                                title="评分详情"
                                OptionsEvent={OptionsEvent}
                                data={{
                                    save: true,
                                    url: 'getScoreManagementGetWinningBidderScoreExcel',
                                    winningBidderUuid,
                                    yearMonth,
                                }}
                            />
                        ),
                        <InputButton
                            key="put"
                            OptionsEvent={OptionsEvent}
                            title="加分"
                            data={{
                                record,
                                actionRef,
                                label: '分数',
                                smallTitle: '增加分数',
                                url: 'posScoreManagementAddWinningBidderScore',
                                field: 'addScore',
                            }}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
